package com.sskj.lib.util;

import android.content.Context;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.lzy.okgo.request.GetRequest;
import com.sskj.common.base.App;
import com.sskj.lib.R;

public class TipUtil {
    public static MaterialDialog getTip(Context context, String content, OnTipSure onTipSure) {
        return getTip(context, content, context.getString(R.string.lib_sure), onTipSure);
    }

    public static MaterialDialog getTip(Context context, String content, boolean isCancel, OnTipSure onTipSure) {
        return new MaterialDialog.Builder(context)
                .title(App.INSTANCE.getString(R.string.lib_tip))
                .content(content)
                .cancelable(false)
                .autoDismiss(false)
                .positiveText(App.INSTANCE.getString(R.string.lib_sure))
//                .negativeText("")
                .onAny((dialog, which) -> {
                    if (which == DialogAction.POSITIVE) {
                        dialog.dismiss();
                        onTipSure.onSure();
                    } else if (which == DialogAction.NEGATIVE) {
                        dialog.dismiss();
                    }
                }).build();
    }
    public static MaterialDialog getTip(Context context, String content, String sureMsg, OnTipSure onTipSure) {
        return new MaterialDialog.Builder(context)
                .title(R.string.lib_tip)
                .content(content)
                .positiveText(sureMsg)
                .negativeText(R.string.lib_cancel)
                .onAny((dialog, which) -> {
                    if (which == DialogAction.POSITIVE) {
                        dialog.dismiss();
                        onTipSure.onSure();
                    } else if (which == DialogAction.NEGATIVE) {
                        dialog.dismiss();
                    }
                }).build();
    }

    public static MaterialDialog getTip(Context context, String content, String sureMsg, OnTipSure2 onTipSure) {
        return new MaterialDialog.Builder(context)
                .title(R.string.lib_tip)
                .content(content)
                .positiveText(sureMsg)
                .negativeText(R.string.lib_cancel)
                .onAny((dialog, which) -> {
                    if (which == DialogAction.POSITIVE) {
                        dialog.dismiss();
                        onTipSure.onSure();
                    } else if (which == DialogAction.NEGATIVE) {
                        dialog.dismiss();
                        onTipSure.onCancel();
                    }
                }).build();
    }

    public static MaterialDialog getTip(Context context, String title, String content, String sureMsg, OnTipSure onTipSure) {
        return new MaterialDialog.Builder(context)
                .title(title)
                .content(content)
                .positiveText(sureMsg)
                .negativeText(R.string.lib_cancel)
                .onAny((dialog, which) -> {
                    if (which == DialogAction.POSITIVE) {
                        dialog.dismiss();
                        onTipSure.onSure();
                    } else if (which == DialogAction.NEGATIVE) {
                        dialog.dismiss();
                    }
                }).build();
    }

    public interface OnTipSure {
        void onSure();

    }

    public interface OnTipSure2 {
        void onSure();

        void onCancel();
    }
}
